/*package com.mes.web.controller.yzl;


import com.mes.entity.yzl.Condition;
import com.mes.entity.yzl.ListBack;
import com.mes.entity.yzl.Receivable;
import com.mes.entity.yzl.Reconciliation;
import com.mes.entity.yzlExtend.ExtendProductor;
import com.mes.entity.yzlExtend.ExtendReceivable;
import com.mes.entity.yzlExtend.ExtendReconciliation;
import com.mes.service.yzl.JiesuanService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/yzl")
public class JiesuanController {

    @Resource
    JiesuanService jiesuanService;


    //总的结算  统计出所有的对账信息  并添加到对账表中
    @RequestMapping("/ReconciliationJs")
    public @ResponseBody int ReconciliationJs(long id){ //进行一次全部结算
        int isSuccess = 0;

        //统计 (按车种统计出本期出库 和本期出库金额 以及时间 )
        List<ExtendReconciliation> reconciliations = new ArrayList<>();
        //reconciliations = jiesuanService.countAllOne(customerId);
        reconciliations = jiesuanService.countAllOne(id);

        for(ExtendReconciliation r : reconciliations){
            Reconciliation reconciliation = new Reconciliation();
            reconciliation.setMonthQ(r.getMonthQ());
            reconciliation.setMonthP(r.getMonthP());
            reconciliation.setProductorId(r.getProductorId());
            if(r.getMonth1().length() < 2){
                reconciliation.setDateMonth(r.getYear1()+"-0"+r.getMonth1());
            }else{
                reconciliation.setDateMonth(r.getYear1()+"-"+r.getMonth1());
            }
            //reconciliation.setCustomerId(r.getCustomerId());
            jiesuanService.addReconciliation(reconciliation);
        }

        return isSuccess;
    }

    //查询对账表信息  返回列表
    @RequestMapping("/reconciliationList")
    public @ResponseBody ListBack reconciliationList(Condition condition){
        ListBack listBack = new ListBack();

        //查询条件处理
        Sup sup = new Sup();
        condition = sup.tdSet(condition);


        //条件查询总数
        int count = jiesuanService.reconciliationListCount(condition);
        listBack.setTotal(count);
        //
        List<ExtendReconciliation> reconciliations = new ArrayList<>();
        reconciliations = jiesuanService.reconciliationList(condition);

        listBack.setRows(reconciliations);

        return listBack;
    }

    //对账单 单行结算
    @RequestMapping("/reconciliationJsOne")
    public @ResponseBody int reconciliationJsOne(ExtendReconciliation reconciliation){
        int isSuccess = 0;

        //首先查询上月的结存数量
        String lastMonth = "";
        ExtendReconciliation reconciliation2 = new ExtendReconciliation();
        String[] sr = reconciliation.getDateMonth().split("-");
        if(Integer.parseInt(sr[1]) == 1){
            lastMonth = ((Integer.parseInt(sr[0]))-1)+"-12";
        }else{
            int lastMonth1 = Integer.parseInt(sr[1])-1;
            if(lastMonth1 < 10){
                lastMonth = sr[0]+"-0"+lastMonth1;
            }else{
                lastMonth = sr[0]+"-"+lastMonth1;
            }
        }
        reconciliation2.setDateMonth(lastMonth);
        reconciliation2.setProductorId(reconciliation.getProductorId());
        //查询上月的记录
        Reconciliation reconciliation1 = new Reconciliation();
        reconciliation1 = jiesuanService.findReconciliationBytime(reconciliation2);
        //上月的期末结存的数量和金额
        int closingBalanceQ = 0;
        float closingBalanceP = 0;
        if(reconciliation1 != null){
            closingBalanceQ = reconciliation1.getClosingBalanceQ();
            closingBalanceP = reconciliation1.getClosingBalanceP();
        }

        reconciliation.setLastMonthQ(closingBalanceQ);
        reconciliation.setLastMonthP(closingBalanceP);
        //计算得到填写的结算数量
        reconciliation.setMonthSettlementP(reconciliation.getMonthSettlementQ()*reconciliation.getPrice());

        //计算期末结存数量(上月结存(期初结存)+本期出库-本期结算)
        int closingBalanceQ1 = closingBalanceQ+reconciliation.getMonthQ()-reconciliation.getMonthSettlementQ();
        reconciliation.setClosingBalanceQ(closingBalanceQ1);
        //计算本期结存金额
        float closingBalanceP1 = closingBalanceQ1*reconciliation.getPrice();
        reconciliation.setClosingBalanceP(closingBalanceP1);

        //更新这条记录
        isSuccess = jiesuanService.updateReconciliationByid(reconciliation);

        return isSuccess;

    }

    //点击对账单每行  显示该行统计数据的详细出库信息
    @RequestMapping("/reconciliationXq")
    public @ResponseBody List<ExtendProductor> reconciliationXq(Reconciliation reconciliation){
        List<ExtendProductor> extendProductors = new ArrayList<>();
        reconciliation.setDateMonth(reconciliation.getDateMonth()+"-01");
        extendProductors = jiesuanService.reconciliationXq(reconciliation);
        return extendProductors;
    }


    @RequestMapping("/receivableList")
    public @ResponseBody ListBack receivableList(Condition condition){
        ListBack listBack = new ListBack();

        //查询条件处理
        Sup sup = new Sup();
        condition = sup.tdSet(condition);

        //条件查询总数
        int count = jiesuanService.receivableListCount(condition);
        listBack.setTotal(count);
        List<ExtendReceivable> receivables = new ArrayList<>();
        receivables = jiesuanService.receivableList(condition);

        listBack.setRows(receivables);

        return listBack;
    }


    //检查是否对过帐
    @RequestMapping("/checkIsDz")
    public @ResponseBody float checkIsDz(Receivable receivable){
        int isSuccess = 0;
        float sum = 0;
        //期初应收为填写
        //所有产品的结算金额（本期结算金额）
        sum = jiesuanService.checkIsDz(receivable);
        //本期结算
        receivable.setMonthSettlementP(sum);

        //查询出本期到期收款
        Receivable receivable1 = new Receivable();
        receivable1 = jiesuanService.findReceivableBytime(receivable);
        receivable.setId(receivable1.getId());
        //本期应收
        float monthReceivableP = 0;
        monthReceivableP = receivable.getLastMonthP()+receivable1.getThisMonthlastP();
        receivable.setMonthReceivableP(monthReceivableP);
        //本期收款为填写
        //本期待收
        receivable.setMonthCollectionP(monthReceivableP - receivable.getMonthCollectP());
        //期末应收
        receivable.setClosingBalanceP(receivable.getLastMonthP() + sum - receivable.getMonthCollectP());

        isSuccess = jiesuanService.updateReceivable(receivable);

        return sum;
    }

    //总的结算 销售应收 (本期结算金额(所有结算金额) 和 本期到期金额(所有出库金额))
    @RequestMapping("/ReceivableJs")
    public @ResponseBody int ReceivableJs(){

        int isSuccess = 0;

        //先按照客户统计 本期到期金额(所有出库金额)
        List<ExtendReceivable> receivables = jiesuanService.countAllOutlibP();
        for(ExtendReceivable r : receivables){
            Receivable receivable = new Receivable();
            receivable.setCustomerId(r.getCustomerId());
            receivable.setThisMonthlastP(r.getThisMonthlastP());
            if(r.getMonth1().length() < 2){
                receivable.setDateMonth(r.getYear1()+"-0"+r.getMonth1());
            }else{
                receivable.setDateMonth(r.getYear1()+"-"+r.getMonth1());
            }
            //按照统计的数据去计算 本期结算金额(所有结算金额)

            jiesuanService.addReceivable(receivable);
        }

        List<Receivable> receivables = jiesuanService.countAllReceivable();

        for(Receivable receivable : receivables){
            jiesuanService.addReceivable(receivable);
        }

        return isSuccess;

    }
}
*/